package com.example.monitor.controller;

import com.example.monitor.model.DTO.AbnormalTypeQueryDTO;
import com.example.monitor.model.DTO.WorkshopRankQueryDTO;
import com.example.monitor.model.DTO.WorkshopTrendQueryDTO;
import com.example.monitor.model.VO.AbnormalTypeVO;
import com.example.monitor.model.VO.ResultVO;
import com.example.monitor.model.VO.WorkshopRankVO;
import com.example.monitor.model.VO.WorkshopTrendVO;
import com.example.monitor.service.AbnormalTypeService;
import com.example.monitor.service.WorkshopRankService;
import com.example.monitor.service.WorkshopTrendService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/group")
@RequiredArgsConstructor
public class GroupController {

    private final WorkshopRankService workshopRankService;
    private final WorkshopTrendService workshopTrendService;
    private final AbnormalTypeService abnormalTypeService;

    @GetMapping("/workshopRank")
    public ResultVO<List<WorkshopRankVO>> getWorkshopRank(
            @RequestParam(required = false) String workshop,
            @RequestParam(required = false) String alarmType,
            @RequestParam(required = false) String timeRange) {

        WorkshopRankQueryDTO queryDTO = new WorkshopRankQueryDTO();
        queryDTO.setWorkshop(workshop);
        queryDTO.setAlarmType(alarmType);
        queryDTO.setTimeRange(timeRange);

        return workshopRankService.getWorkshopRank(queryDTO);
    }

    @GetMapping("/workshopTrend")
    public ResultVO<WorkshopTrendVO> getWorkshopTrend(
            @RequestParam(required = false) String workshop,
            @RequestParam(required = false) String timeRange) {

        WorkshopTrendQueryDTO queryDTO = new WorkshopTrendQueryDTO();
        queryDTO.setWorkshop(workshop);
        queryDTO.setTimeRange(timeRange);

        return workshopTrendService.getWorkshopTrend(queryDTO);
    }

    @GetMapping("/abnormalTypeDistribution")
    public ResultVO<List<AbnormalTypeVO>> getAbnormalTypeDistribution(
            @RequestParam(required = false) String workshop,
            @RequestParam(required = false) String timeRange) {

        AbnormalTypeQueryDTO queryDTO = new AbnormalTypeQueryDTO();
        queryDTO.setWorkshop(workshop);
        queryDTO.setTimeRange(timeRange);

        return abnormalTypeService.getAbnormalTypeDistribution(queryDTO);
    }
}
